<?php

namespace App\Kuafu\Pay\Model;

use App\Kuafu\Base\Model\BaseModel;
use App\Kuafu\Base\Model\Traits\KfSoftDeletes;
use App\Kuafu\Base\Model\Traits\KfUid;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class CheckFileModel extends BaseModel
{
    use KfSoftDeletes;

    protected $connection = 'mysql';
    protected $table      = 'check_files';
    protected $primaryKey = 'id';

    protected $fillable = [
        'date',
        'payChannel',
        'sysType',
        'urlPath',
        'company',
    ];

    public function getUrlAttribute(): string
    {
        return ossPublicFilePath($this->urlPath);
    }

    public static function addData(int $date, int $payChannel, int $company, string $path)
    {
        return CheckFileModel::query()->create([
            'payChannel' => $payChannel,
            'company'    => $company,
            'date'       => $date,
            'urlPath'    => $path,
        ]);
    }

    public static function delData(int $date, int $payChannel, int $company)
    {
        return self::query()
                   ->where('date', $date)
                   ->where('payChannel', $payChannel)
                   ->where('company', $company)
                   ->update(['isDeleted' => 1]);
    }
}
